package com.cyh.demo;

import com.cyh.dao.UserDao;
import com.cyh.service.UserService;
import com.cyh.service.impl.UserServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class UserController {
    //模拟ssm访问
    public static void main(String[] args) {
        //模拟ssm方法一 新建
        /*UserService userService  = new UserServiceImpl();
        userService.save();*/

        //模拟ssm方法二 配置文件配置
        /*ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService1 = (UserService) app.getBean("userService");
        userService1.save();*/

        /*ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService2 = (UserService) app.getBean("userService2");
        userService2.save();*/

        //将上面的改成p命名空间表示法
        /*ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService3 = (UserService) app.getBean("userService3");
        userService3.save();*/

        ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService4 = (UserService) app.getBean("userService4"); //常用
        //UserService userService4 = app.getBean(UserService.class); //只在配置文件中只有一个UserService时使用
        userService4.save();

        //AnnotationConfigApplicationContext//当使用注解配置容器对象时，需要使用此类来创建spring容器，它用来读取注解
        //FileSystemXmlApplicationContext //它是从磁盘路径上加载配置文件，可以在磁盘的任意位置
        //ClassPathXmlApplicationContext //它是从类的根路径加载配置文件推荐使用这种

    }
}
